<ng-select
  [items]="baseItems()"
  [(ngModel)]="selectedItems"
  (ngModelChange)="onChange($event)"
  (blur)="onBlur()"
  bindLabel="listName"
  groupBy="parentGrouping"
  [placeholder]="placeholder()"
  [loading]="loading()"
  [loadingText]="loadingText"
  notFoundText="{{ 'multiSelectNotFound' | i18n }}"
  clearAllText="{{ 'multiSelectClearAll' | i18n }}"
  [multiple]="true"
  [closeOnSelect]="false"
  (close)="onDropdownClosed()"
  [disabled]="disabled"
  [clearSearchOnAdd]="true"
  [labelForId]="labelForId"
  [keyDownFn]="keyDown"
  appendTo="body"
>
  <ng-template ng-loadingspinner-tmp>
    <i class="bwi bwi-spinner bwi-spin tw-me-1" [title]="loadingText" aria-hidden="true"></i>
  </ng-template>
  <ng-template ng-label-tmp let-item="item" let-clear="clear">
    <button
      type="button"
      bitBadge
      variant="primary"
      class="tw-me-1 disabled:tw-border-0 tw-flex tw-gap-1.5 tw-items-center"
      [disabled]="disabled"
      (click)="clear(item)"
    >
      @if (item.icon != null) {
        <i class="bwi bwi-fw {{ item.icon }}" aria-hidden="true"></i>
      }
      <span class="tw-truncate">
        {{ item.labelName }}
      </span>
      <i class="bwi bwi-fw bwi-close bwi-sm" aria-hidden="true"></i>
    </button>
  </ng-template>
  <ng-template ng-option-tmp let-item="item">
    <div class="tw-flex">
      <div class="tw-w-7 tw-flex-none">
        @if (isSelected(item)) {
          <i class="bwi bwi-fw bwi-check" aria-hidden="true"></i>
        }
      </div>
      <div class="tw-me-2 tw-flex-initial">
        @if (item.icon != null) {
          <i class="bwi bwi-fw {{ item.icon }}" aria-hidden="true"></i>
        }
      </div>
      <div class="tw-flex-1">
        {{ item.listName }}
      </div>
    </div>
  </ng-template>
</ng-select>
